package com.wcgksoft.mobileservice.Account;

import com.wcgksoft.common.util.MsgInfo;
import com.wcgksoft.entity.system.SysUser;
import com.wcgksoft.service.system.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 阿良
 * @version 1.0.0
 * @ClassName AppUserController.java
 * @Description 移动端接口小程序app
 * @createTime 2020年03月09日 11:48:00
 */

@Controller
@RequestMapping("mobile/user")
public class AppUserController {

  @Autowired
  private UserService userService;

  @ResponseBody
  @RequestMapping(value = "login")
  public MsgInfo list(HttpServletRequest request,
                      @RequestParam(value = "username", required = true) String username,
                      @RequestParam(value = "password", required = true) String password) {
    MsgInfo msgInfo = new MsgInfo();
    //String md5Password = PasswordUtil.encrypt(username, password, PasswordUtil.getStaticSalt());
    SysUser baseUser = userService.loginSysUser(username, password);
    if (baseUser == null) {
      msgInfo.setCode(1);
      msgInfo.setMsg("账号或密码错误！");
      return msgInfo;
    } else {
      msgInfo.setCode(0);
      msgInfo.setMsg("登录成功");
      msgInfo.setData(baseUser);
      return msgInfo;
    }
  }
}
